package com.tanguy.driver.ui.account.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tanguy.driver.R;
import com.tanguy.driver.bean.car.CarModelBean;
import com.tanguy.driver.interfaces.OnDataCallBack;

import java.util.List;


/**
 * Created by dab on 2017/8/14 0014 18:06
 * 车辆类型
 */

public class BatchTypeAdapter extends RecyclerView.Adapter<BatchTypeAdapter.ViewHolder> {
    private List<CarModelBean> mCarTypesBeans;
    private OnDataCallBack<CarModelBean> mDataCallBack;

    public void setDataCallBack(OnDataCallBack<CarModelBean> dataCallBack) {
        mDataCallBack = dataCallBack;
    }

    public void setCarTypesBeans(List<CarModelBean> carTypesBeans) {
        mCarTypesBeans = carTypesBeans;
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_car_brand_type, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        CarModelBean carModelBean = mCarTypesBeans.get(position);
        holder.mTvType.setText(carModelBean.getName());
        if (mDataCallBack != null) {
            holder.itemView.setOnClickListener(view -> mDataCallBack.onCallBack(carModelBean));
        }


    }

    @Override
    public int getItemCount() {
        return mCarTypesBeans == null ? 0 : mCarTypesBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView mTvType;

        public ViewHolder(View itemView) {
            super(itemView);
            mTvType = itemView.findViewById(R.id.tv_type);

        }
    }
}
